package com.prs.crm.action.sys;

import java.io.File;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.context.FileUtil;
import com.prs.crm.domain.sys.WireInformation;
import com.prs.crm.service.sys.WireInformationService;

public class WireInformationAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private WireInformation wireInformation;
	private WireInformationService wireInformationService;
	private File upload;
	private String uploadFileName;
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public WireInformation getWireInformation() {
		return wireInformation;
	}
	public void setWireInformation(WireInformation wireInformation) {
		this.wireInformation = wireInformation;
	}
	public WireInformationService getWireInformationService() {
		return wireInformationService;
	}
	public void setWireInformationService(
			WireInformationService wireInformationService) {
		this.wireInformationService = wireInformationService;
	}
	
	@Action("listWireInformation")
	public String listWireInformation(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(WireInformation.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getWireInformationService().listByPage(criteria, pagination)); 
		return SUCCESS;
	}
	
	@Action("editWireInformation")
	public String editWireInformation(){
		if(ids!=null){
			this.wireInformation=this.getWireInformationService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action(value="saveWireInformation",results={
			@Result(name="success",type="redirect",location="listWireInformation"),
			@Result(name="error",type="chain",location="editWireInformation")
	})
	public String saveWireInformation(){
		if (upload!=null) {
			this.wireInformation.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		if (wireInformation.getName()==null || "".equals(wireInformation.getName().trim())) {
			addActionError("开户名不能为空！");
			return ERROR;
		}
		if (wireInformation.getNumber()==null || "".equals(wireInformation.getNumber().trim()))  {
			addActionError("开户账号不能为空！");
			return ERROR;
		}
		if (wireInformation.getBank()==null || "".equals(wireInformation.getBank().trim())) {
			addActionError("开户银行不能玩为空！");
			return ERROR;
		}
		this.getWireInformationService().save(wireInformation);
		return SUCCESS;
	}
	@Action(value="saveWireInformations",results={
			@Result(name="success",type="redirect",location="editWireInformation"),
			@Result(name="error",type="chain",location="editWireInformation")
	})
	public String saveWireInformations(){
		if (upload!=null) {
			this.wireInformation.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		if (wireInformation.getName()==null || "".equals(wireInformation.getName().trim())) {
			addActionError("开户名不能为空！");
			return ERROR;
		}
		if (wireInformation.getNumber()==null || "".equals(wireInformation.getNumber().trim()))  {
			addActionError("开户账号不能为空！");
			return ERROR;
		}
		if (wireInformation.getBank()==null || "".equals(wireInformation.getBank().trim())) {
			addActionError("开户银行不能玩为空！");
			return ERROR;
		}
		this.getWireInformationService().save(wireInformation);
		return SUCCESS;
	}
	
	@Action(value="removeWireInformation",results={
			@Result(name="success",type="redirect",location="listWireInformation"),
			@Result(name="error",type="chain",location="listWireInformation")
	})
	public String removeWireInformation(){
		if (ids!=null) {
			this.wireInformation=this.getWireInformationService().get(ids[0]);
		}
		this.getWireInformationService().batchRemove(ids);
		return SUCCESS;
	}
}
